package com.ddd.wandemo;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.base.BaseActivity;
import com.bean.SearchHotKeyBean;
import com.bean.ToDoBean;
import com.gcssloop.widget.PagerGridLayoutManager;
import com.ui.other.OtherFragment;
import com.widget.DaySelectTabLayout;

import java.util.ArrayList;
import java.util.List;

public class SplashActivity extends BaseActivity<SplashPresenter> implements SplashContract.View, PagerGridLayoutManager
        .PageListener {
    private DaySelectTabLayout mTest2;
    private ViewPager mVpSplash;
    private List<Fragment> mFragments = new ArrayList<>();

    @Override
    protected void setContentLayout() {
        //        setTheme(R.style.BaseAppTheme);
        setContentView(layoutId);
    }

    @Override
    protected int setLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected SplashPresenter initPresenter() {
        return new SplashPresenter();
    }

    @Override
    protected void initView() {
//        mVpSplash = findViewById(R.id.vp_splash);
//        mTest2 = findViewById(R.id.test2);

    }

    @Override
    public void onGetTodo(ToDoBean bean) {

    }

    @Override
    protected void initEvent() {
        //        handler.postDelayed(new Runnable() {
        //            @Override
        //            public void run() {
        //                Intent intent = new Intent(SplashActivity.this,MainActivity.class);
        //                startActivity(intent);
        //                SplashActivity.this.finish();
        //            }
        //        },1500);
//        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
//        startActivity(intent);
//        SplashActivity.this.finish();
        List<SearchHotKeyBean> data = new ArrayList<>();
        for (int i = 0; i < 14; i++) {
            SearchHotKeyBean bean = new SearchHotKeyBean();
            bean.setName(i+"");
            if (i == 9) {
                bean.setVisible(1);
            }else {
                bean.setVisible(0);
            }
            data.add(bean);
        }
        for (int i = 0; i < data.size(); i++) {
            mFragments.add(OtherFragment.newInstance(i+""));
        }


        SplashVpAdapter homeVpAdapter = new SplashVpAdapter(getSupportFragmentManager());
        mVpSplash.setAdapter(homeVpAdapter);
        mVpSplash.setOffscreenPageLimit(mFragments.size());


        mTest2.setData(data);
        mTest2.setSelectedListener(new DaySelectTabLayout.SelectedListener() {
            @Override
            public void selectedPosition(int position) {
                mVpSplash.setCurrentItem(position);
            }
        });

        mVpSplash.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                mTest2.changeSelected(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        mPresenter.getTodoList(-1,-1,1);

    }

    public class SplashVpAdapter extends FragmentPagerAdapter {
        public SplashVpAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments == null ? 0 : mFragments.size();
        }
    }

    @Override
    public void onPageSizeChanged(int pageSize) {

    }

    @Override
    public void onPageSelect(int pageIndex) {

    }
}
